package com.xveshe.admin.service.impl;

import java.util.List;
import java.util.UUID;

import com.xveshe.admin.domain.XsglXsxx;
import com.xveshe.admin.mapper.XsglXsxxMapper;
import com.xveshe.common.utils.DateUtils;
import com.xveshe.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xveshe.admin.mapper.XsglTstgMapper;
import com.xveshe.admin.domain.XsglTstg;
import com.xveshe.admin.service.IXsglTstgService;

/**
 * 调社调岗Service业务层处理
 *
 * @author geyasong
 * @date 2024-11-06
 */
@Service
public class XsglTstgServiceImpl implements IXsglTstgService
{
    @Autowired
    private XsglTstgMapper xsglTstgMapper;
    @Autowired
    private XsglXsxxMapper xsglXsxxMapper;

    /**
     * 查询调社调岗
     *
     * @param id 调社调岗主键
     * @return 调社调岗
     */
    @Override
    public XsglTstg selectXsglTstgById(String id)
    {
        return xsglTstgMapper.selectXsglTstgById(id);
    }

    /**
     * 查询调社调岗列表
     *
     * @param xsglTstg 调社调岗
     * @return 调社调岗
     */
    @Override
    public List<XsglTstg> selectXsglTstgList(XsglTstg xsglTstg)
    {
        if(!(SecurityUtils.getUsername().equals("admin")||SecurityUtils.hasRole("guanli")
                ||SecurityUtils.getUsername().contains("x"))){
            XsglXsxx xsxx = new XsglXsxx();
            xsxx.setXsxxXsds(SecurityUtils.getUsername());
            xsxx.setXsxxQyds(SecurityUtils.getUsername());
            xsglTstg.setTstgXsmc(xsglXsxxMapper.selectXsglXsxx(xsxx).getId());
        }
        return xsglTstgMapper.selectXsglTstgList(xsglTstg);
    }

    /**
     * 新增调社调岗
     *
     * @param xsglTstg 调社调岗
     * @return 结果
     */
    @Override
    public int insertXsglTstg(XsglTstg xsglTstg)
    {
        xsglTstg.setId(UUID.randomUUID().toString());
        //获取用户账号xsglXslb.setCreator(SecurityUtils.getUsername());
        //获取用户昵称
        xsglTstg.setCreator(SecurityUtils.getLoginUser().getUser().getNickName());
        xsglTstg.setCreatedate(DateUtils.getNowDate());
        return xsglTstgMapper.insertXsglTstg(xsglTstg);
    }

    /**
     * 修改调社调岗
     *
     * @param xsglTstg 调社调岗
     * @return 结果
     */
    @Override
    public int updateXsglTstg(XsglTstg xsglTstg)
    {
        xsglTstg.setLastmodifier(SecurityUtils.getLoginUser().getUser().getNickName());
        xsglTstg.setLastmodifieddate(DateUtils.getNowDate());
        return xsglTstgMapper.updateXsglTstg(xsglTstg);
    }

    /**
     * 批量删除调社调岗
     *
     * @param ids 需要删除的调社调岗主键
     * @return 结果
     */
    @Override
    public int deleteXsglTstgByIds(String[] ids)
    {
        return xsglTstgMapper.deleteXsglTstgByIds(ids);
    }

    /**
     * 删除调社调岗信息
     *
     * @param id 调社调岗主键
     * @return 结果
     */
    @Override
    public int deleteXsglTstgById(String id)
    {
        return xsglTstgMapper.deleteXsglTstgById(id);
    }
}
